 

package com.zdkj.subway.stm.controller;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.util.SecurityUtils;
import com.zdkj.subway.stm.entity.SwStTvmSupplementCurrencyDetails;
import com.zdkj.subway.stm.entity.SwStTvmCheckDetailCoinChange;
import com.zdkj.subway.stm.reportquery.util.StationSettleUtil;
import com.zdkj.subway.stm.service.SwStTvmSupplementCurrencyDetailsService;
import org.springframework.security.access.prepost.PreAuthorize;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 
 *
 * @author songtuo
 * @date 2020-07-09 10:33:25
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swsttvmsupplementcurrencydetails" )
@Api(value = "swsttvmsupplementcurrencydetails", tags = "管理")
public class SwStTvmSupplementCurrencyDetailsController {

    private final  SwStTvmSupplementCurrencyDetailsService swStTvmSupplementCurrencyDetailsService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param swStTvmSupplementCurrencyDetails 
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getSwStTvmSupplementCurrencyDetailsPage(Page page, SwStTvmSupplementCurrencyDetails swStTvmSupplementCurrencyDetails) {
        return R.ok(swStTvmSupplementCurrencyDetailsService.page(page, Wrappers.query(swStTvmSupplementCurrencyDetails)));
    }


    /**
     * 通过id查询
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(swStTvmSupplementCurrencyDetailsService.getById(id));
    }

    /**
     * 新增
     * @param swStTvmSupplementCurrencyDetails 
     * @return R
     */
    @ApiOperation(value = "新增", notes = "新增")
    //@SysLog("新增" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('generator_swsttvmsupplementcurrencydetails_add')" )
    public R save(@RequestBody SwStTvmSupplementCurrencyDetails swStTvmSupplementCurrencyDetails) {
        return R.ok(swStTvmSupplementCurrencyDetailsService.save(swStTvmSupplementCurrencyDetails));
    }

    /**
     * 修改
     * @param swStTvmSupplementCurrencyDetails 
     * @return R
     */
    @ApiOperation(value = "修改", notes = "修改")
    //@SysLog("修改" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('generator_swsttvmsupplementcurrencydetails_edit')" )
    public R updateById(@RequestBody SwStTvmSupplementCurrencyDetails swStTvmSupplementCurrencyDetails) {
        return R.ok(swStTvmSupplementCurrencyDetailsService.updateById(swStTvmSupplementCurrencyDetails));
    }

    /**
     * 通过id删除
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除", notes = "通过id删除")
    //@SysLog("通过id删除" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('generator_swsttvmsupplementcurrencydetails_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(swStTvmSupplementCurrencyDetailsService.removeById(id));
    }
	 /**
     * 获取已经补币的TVM编号和钱箱编号
     * @param revenueTime 收益日期
     * @param tvmCashBoxType 4:纸币找零箱     2:硬币找零箱
     * @return
     */
    @ApiOperation(value = "TVM编号查询", notes = "TVM编号查询")  
    //@GetMapping("/haveTvmCode/{revenueTime}/{tvmCashBoxType}/{tvmCode}" )
    //public R getSwStTvmHaveSupplement(@PathVariable("revenueTime" ) String revenueTime,@PathVariable("tvmCashBoxType" ) String tvmCashBoxType,@PathVariable("tvmCode" ) String tvmCode) {
	@GetMapping("/haveTvmCode/{revenueTime}/{tvmCashBoxType}/{flag}" )
     public R getSwStTvmHaveSupplement(@PathVariable("revenueTime" ) String revenueTime,@PathVariable("tvmCashBoxType" ) String tvmCashBoxType,@PathVariable("flag" ) String flag) {
       	String lineCode=SecurityUtils.getUser().getLineCode();    	
	    String stationCode=SecurityUtils.getUser().getStationCode();
		//String flag = "1";  //需要根据业务调整，如果是正常的获取1，否则传2
	      
        List<SwStTvmCheckDetailCoinChange> lstReturn = new ArrayList<SwStTvmCheckDetailCoinChange>();
		List<Map<String, Object>> lstSupplement = StationSettleUtil.getSupplmentInfo(lineCode,stationCode,tvmCashBoxType,revenueTime,null,flag);
	    if(lstSupplement!=null && lstSupplement.size()>0){
		        for(int i=0;i<lstSupplement.size();i++){
				   Map<String,Object>  map  = lstSupplement.get(i);
		           SwStTvmCheckDetailCoinChange cashBox = new SwStTvmCheckDetailCoinChange();
			       cashBox.setTvmCode(String.valueOf(map.get("tvmcode")));
			       //cashBox.setCashboxCode(String.valueOf(map.get("cashboxcode")));
			       lstReturn.add(cashBox);
				
				}
		}	
		
		return R.ok(lstReturn);
     	
    }

}
